package com.jeesite.modules.stock.assembler;

import com.jeesite.modules.stock.service.StockLogoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class StockDailyDataAssembler {
    @Autowired
    private StockLogoService stockLogoService;

    private Object renderStockFieldValue(Object value) {
        if (value == null) {
            return value;
        }
        if (value instanceof Boolean bv) {
            return (bv) ? "是" : "否";
        }
        return value;
    }


    public void convert2VO(Map<String, Object> data) {
        for (String key : data.keySet()) {
            Object value = data.get(key);
            if ("logo".equals(key)) {
                value = stockLogoService.getLogoUrl(String.valueOf(data.get("stockCode")), String.valueOf(value), String.valueOf(data.get("exchange")));
            }
            data.put(key, renderStockFieldValue(value));
        }
    }
}
